Database functions ?

  • CRUD functions

    1. Create / Save data

    1. using insert()

    2. first parameter is table name

    3. second parameter is array data

    
    
                      $data = array(
                          'name' => 'John',
                          'email' => 'john@example.com'
                      );
                      $this->db->insert('users', $data);
    
                      

    2. Read data

    1. using get() & result() : for multiple records

    
                        $this->db->where('status', 'A');
                        $query = $this->db->get('users');
    
                        //return array of object 
                        $result= $query->result();
    
                        OR
    
                        //return array of array
                        $result= $query->result_array()
                      

    2. using get() & row() : for single records

    
                        $this->db->where('status', 'A');
                        $query = $this->db->get('users');
    
                        //return single object
                        $row= $query->row();
    
                        OR
    
                        //return single array
                        $row= $query->row_array();
    
                      

    3. update

    1. using update()

    2. first parameter is table

    3. second parameter is array data

    
                        $this->db->where('id', 1);
                        $this->db->update('users', ['status' => 'active']);
                      

    4. Delete

    
                        $this->db->where('id', 1);
                        $this->db->delete('users');
                      
  • Where Condition functions

    where()
    
                            $this->db->where('status', 'active');
                          
    or_where()
    
                            $this->db->or_where('type', 'admin');
                          
    where_in()
    
                            $this->db->where_in('id', [1, 2, 3]);